/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.jacusoft.annotation.jdbc.processor;

import java.util.Calendar;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import org.jacusoft.annotation.jdbc.Password;
import org.jacusoft.annotation.jdbc.Username;
import org.jacusoft.annotation.SingleAnnotationProcessor;

/**
 *
 * @author bc548
 */
@SupportedAnnotationTypes("org.jacusoft.annotation.jdbc.DatabaseConnection")
@SupportedSourceVersion(SourceVersion.RELEASE_7)
public class DatabaseConnectionProcessor extends SingleAnnotationProcessor {

  @Override
  protected void processAnnotation(Class annotationClass,Element annotatedElement, RoundEnvironment roundEnv) {
    String template = this.getResourceAsText("codegenerator/templates/ConnectionFactory.template");
    //
    TypeElement classElement = (TypeElement) annotatedElement;
    //
    String strDate=Calendar.getInstance().getTime().toString();
    String packageName = ((PackageElement) annotatedElement.getEnclosingElement()).getQualifiedName().toString();
    String className=classElement.getSimpleName().toString();
    String username=this.getStringFieldValue(this.getEnclosedFieldAnnotatedWith(annotatedElement, Username.class));
    String password=this.getStringFieldValue(this.getEnclosedFieldAnnotatedWith(annotatedElement, Password.class));;
    
    System.out.println("**************** "+strDate);
    System.out.println("**************** "+packageName);
    System.out.println("**************** "+className);
    System.out.println("**************** "+username);
    System.out.println("**************** "+password);
    
    
    
    
//    try {
//      BufferedWriter writer = this.getSourceFileWriter("");
//      //
//      
//      //
//      writer.flush();
//      writer.close();
//    } catch (Exception e) {
//      this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage());
//    }

  }

}
